//
//  TTOtherView.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/24.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit
import SnapKit
class TTOtherView: UIView {

    var centerViewContrain:Constraint?
    
    var tthomeModel:TTHomeCellModel?{
        
        didSet{
            
            textLable.text = tthomeModel?.cellModel?.retweeted_status?.text
            
//            print(tthomeModel?.cellModel?.retweeted_status?.pic_urls)
            
            self.centerViewContrain?.uninstall()
            
            if tthomeModel?.cellModel?.retweeted_status?.pic_urls?.count <= 0{
                
                self.snp_makeConstraints { (make) -> Void in
                    
                    self.centerViewContrain = make.bottom.equalTo(textLable.snp_bottom).offset(10).constraint
                    
                    
                }
                pictureView.hidden = true
                
            }else{
                
                pictureView.tthomeModel = tthomeModel?.cellModel?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints { (make) -> Void in
                    
                    self.centerViewContrain = make.bottom.equalTo(pictureView.snp_bottom).offset(10).constraint
                    
                }
                
                pictureView.hidden = false
                
            }

        }
    }


    lazy var pictureView:TTPictureView = TTPictureView()
    
    override init(frame: CGRect) {
//        
        super.init(frame: frame)
        
        setUpUI()
    }
    
    func setUpUI(){
        
        addSubview(textLable)
        addSubview(pictureView)
        
        textLable.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self).offset(10)
            make.leading.equalTo(self).offset(10)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(textLable.snp_bottom).offset(10)
            make.leading.equalTo(self).offset((375-250)/2)
        }
//
        self.snp_makeConstraints { (make) -> Void in
            
           self.centerViewContrain = make.bottom.equalTo(textLable).offset(10).constraint
        }
    }
    
    
    lazy var textLable:UILabel = {
       let text = UILabel()
        text.font = UIFont.systemFontOfSize(16)
        text.textColor = UIColor.lightGrayColor()
        text.preferredMaxLayoutWidth = SCREENW - 20
        text.numberOfLines = 0
        return text
    }()
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
